package com.lz.ht.service.serviceImpl;

import com.lz.ht.dao.CustomerMapper;
import com.lz.ht.dao.CustomersDao;
import com.lz.ht.model.Customer;
import com.lz.ht.model.Customers;
import com.lz.ht.page.PageModel;
import com.lz.ht.service.CustomersService;
import com.lz.ht.util.ToolKit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

/**
 * @ClassName: CustomersService
 * @Description:
 * @Author: CHonghao
 * @Date: 2021/7/8 11:27
 * @Version: V1.0
 **/

@Service
@Transactional(rollbackFor = Exception.class)
public class CustomersServiceImpl implements CustomersService {

    @Autowired
    private CustomersDao customersDao;

    @Override
    public List<Customers> findPageList(PageModel<Customers> page, Customers customers) throws Exception {
        HashMap<String, Object> hashMap = ToolKit.javaBeanToMap(customers);
        List<Customers> pageList = findListByMapLimit(hashMap, page.getMsFirst(), page.getMsLast());
        return pageList;
    }

    @Override
    public List<Customers> findListByMapLimit(HashMap<String,Object> hashMap,long first,long last){
        hashMap.put("msFirst",first);
        hashMap.put("msLast",last);
        return customersDao.findListByMapLimit(hashMap);
    }

    @Override
    public long findCount(Customers  customers) throws Exception {
        HashMap<String, Object> hashMap = ToolKit.javaBeanToMap(customers);
        return  findCountByMap(hashMap);
    }
    @Override
    public long findCountByMap(HashMap<String,Object> hashMap){
        return customersDao.findCountByMap(hashMap);
    }

    @Override
    public void add(Customers record) {
        customersDao.add(record);
    }

    @Override
    public Customers findById(String cid) {
        return customersDao.selectByPrimaryKey(cid);
    }

    @Override
    public void updateById(Customers customers) {
        customersDao.updateByPrimaryKeySelective(customers);
    }

    @Override
    public int deleteById(String cid) {
        return customersDao.deleteByPrimaryKey(cid);
    }

}
